<template>
	<view>
		<view class="">
			<image class="login-img" src="/static/images/login.jpg" mode="widthFix"></image>
		</view>
		<!-- <view class="blank30"></view> -->
		<view class="blank30"></view>
		<view class="wrapper">
			<view class="">
				<u--form labelPosition="top" :model="form" ref="uForm" errorType="toast">
					<u-form-item prop="mobile">
						<u--input v-model="form.login" border="none" fontSize="14" :customStyle="inputCustomStyle"
							placeholder="请输入登录账号" clearable></u--input>
					</u-form-item>
					<view>
						<u-form-item prop="pwd" v-if="openEye">
							<!-- #ifndef APP-NVUE -->
							<u-input v-model="form.pwd" border="none" fontSize="14" :customStyle="inputCustomStyle"
								placeholder="请输入登录密码" type="text" clearable>
								<!-- #endif -->
								<!-- #ifdef APP-NVUE -->
								<u--input v-model="form.pwd" border="none" fontSize="14" :customStyle="inputCustomStyle"
									placeholder="请输入登录密码" type="text" clearable>
									<!-- #endif -->
									<view class="" slot="suffix" @click="openEye = !openEye">
										<u-icon name="eye" color="#999999" size="18"></u-icon>
									</view>
							<!-- #ifndef APP-NVUE -->
							</u-input>
							<!-- #endif -->
							<!-- #ifdef APP-NVUE -->
							</u--input>
							<!-- #endif -->
						</u-form-item>
						<u-form-item prop="pwd" v-if="!openEye">
							<!-- #ifndef APP-NVUE -->
							<u-input v-model="form.pwd" border="none" fontSize="14" :customStyle="inputCustomStyle"
								placeholder="请输入登录密码" type="password" clearable>
								<!-- #endif -->
								<!-- #ifdef APP-NVUE -->
								<u--input v-model="form.pwd" border="none" fontSize="14" :customStyle="inputCustomStyle"
									placeholder="请输入登录密码" :type="password" clearable>
									<!-- #endif -->
									<view class="" slot="suffix" @click="openEye = !openEye">
										<u-icon name="eye-off" color="#999999" size="18"></u-icon>
									</view>
							<!-- #ifndef APP-NVUE -->
							</u-input>
							<!-- #endif -->
							<!-- #ifdef APP-NVUE -->
							</u--input>
							<!-- #endif -->
						</u-form-item>
					</view>
					<!-- <u-form-item>
						<view class="flex justify-between" style="width: 100%;">
							<view class="flex flex-1">
								
							</view>
							<view class="font-22 u-content-color">
								忘记密码?
							</view>
						</view>
					</u-form-item> -->
				</u--form>
			</view>
			<u-gap height="30"></u-gap>
			<view class="wrapper">
				<u-button type="primary" text="登录" shape="circle"  @click="pwLogin" class="btn-submit"></u-button>
			</view>
		</view>

		<u-gap height="30"></u-gap>
	</view>
</template>

<script>
	import {
		get_session_info,
		login,
		login_new,
		material_static_data,
		purchase_material_item,
		dish_material_common_data
	} from '@/common/api.js';
	export default {
		data() {
			return {
				tabIndex: 0,
				form: {
					login: '',//张涛
					pwd: '',//zt1112
				},
				// rules: {
				// 	'login': {
				// 		type: 'string',
				// 		required: true,
				// 		message: '请填写登录账号',
				// 		trigger: ['blur', 'change']
				// 	},
				// },
				inputCustomStyle: {
					backgroundColor: '#f7f7f7',
					padding: '10px 15px'
				},
				openEye: false,
				isAgree: true,
				tips: '',

				wxLoginData: {},
				sessionKey: '',
				member_file:'',
				server_file:''
			}
		},
		watch: {

		},
		methods: {
			// 密码登录
			pwLogin(){
				if (!this.form.login) {
					uni.$u.toast('请输入登录账号');
					return false;
				}
				if (!this.form.pwd) {
					uni.$u.toast('请输入登录密码');
					return false;
				}
				uni.showLoading({
					title: '提交中'
				})
				let data = {
					login:this.form.login,
					password:this.form.pwd,
				};
				uni.setStorageSync('loginInfo', data)
				login(data,{
				 	header:{
						'Content-Type':'application/x-www-form-urlencoded'
					}
				}).then(async (res) => {
					console.log(res);
					if(res == '登陆成功'){
						// await this.get_dish_material_common_data();
						// await this.get_material_static_data();
						await this.get_session_info();
						
						uni.$u.toast('登录成功');
						setTimeout(() => {
							// uni.$u.route({
							// 	url: 'pages/index/index',
							// 	type: 'switchTab'
							// })
							uni.$u.route({
								url: 'pages/index/index',
								type: 'reLaunch'
							})
						}, 2000);
						// this.get_purchase_material_item();
					}else{
						uni.$u.toast(res);
					}
				}).catch((res) => {
					console.log(res);
					if(typeof res == 'object'){
						uni.$u.toast(res.data);
					}else{
						uni.$u.toast(res || '错误-login');
					}
					
					
				}).finally(() => {
					// uni.hideLoading();
				})	
			},
			get_purchase_material_item(){
				purchase_material_item().then((res) => {
					this.$store.commit('set_material_item', res.result);	
				}).catch(() => {
				
				}).finally(() => {
					
				})
			},
			getData(){
				
			}
		},
		onLoad() {
			// this.getData();
			try{
				let loginInfo = uni.getStorageSync('loginInfo') || {};
				this.form.login = loginInfo.login;
				this.form.pwd = loginInfo.password;
			}catch(e){
				
			}
		},
	}
</script>
<style>
	page {
		background-Color: #fff
	}
</style>

<style lang="scss" scoped>
	page {
		background-color: #ffffff;
	}

	.wrapper {
		padding: 0 47upx;
		background-color: #ffffff;
	}
	.login-img{
		width: 750upx;
	}
</style>
